package com.gzedu.module.faced.curd.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gzedu.module.faced.curd.CurdButtonFacade;
import com.gzedu.module.modle.curd.CurdButton;
import com.gzedu.module.service.curd.ICurdButtonService;

@Service
public class CurdButtonFacadeImpl implements CurdButtonFacade{
	@Autowired
	private ICurdButtonService curdButtonService;

	public boolean insert(CurdButton curdButton) {
		// TODO Auto-generated method stub
		return curdButtonService.insert(curdButton) > 0;
	}

	public List<CurdButton> getBtnInfo(String curd_form_id) {
		// TODO Auto-generated method stub
		CurdButton curdButton = new CurdButton();
		curdButton.setCurd_form_id(curd_form_id);
		return curdButtonService.selectByFormId(curdButton);
	}

	public List<Map<String, Object>> getBtnInfoByFormId(String curd_form_id) {
		// TODO Auto-generated method stub
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		List<CurdButton> list = this.getBtnInfo(curd_form_id);
		if(list != null && list.size() > 0){
			for(CurdButton btn : list){
				StringBuffer str = new StringBuffer();
				str.append(btn.getButton_id()).append(",").append(btn.getButton_name())
					.append(",").append(btn.getOnclick());
				
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("btn", str.toString());
				map.put("btnId", btn.getButton_id());
				map.put("btnName", btn.getButton_name());
				res.add(map);
			}
		}
		return res;
	}

}
